package com.example.hosptialtag.controller;

import com.example.hosptialtag.service.BindService;
import com.example.hosptialtag.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @Author liuyuhao&caiang
 * @Date 2022/2/21
 */

@Controller
public class TagController {
@Autowired
private TagService tagService;
@Autowired
private BindService bindService;
@RequestMapping(value = "/createTag")//创建有时间限制的标签
    public String createTag(String tag_name, Integer tag_group, String tag_start_time,
                            String tag_end_time, int tag_office, int tag_weight, int oid, int role, Model model){
    return tagService.createTag(tag_name, tag_group, tag_start_time, tag_end_time,
            tag_office, tag_weight, oid, role, model);
}

@RequestMapping(value = "/deleteTagById")//根据tag_id删除tag
    public String deleteTagById(int tag_id, int tag_group, int tag_office, int tag_weight, int oid, int role, Model model){
    bindService.deleteBindByTagId(tag_id, model);//同时删除tag相关的绑定
    return tagService.deleteTagById(tag_id, tag_group, tag_office, tag_weight, oid, role, model);
}

@RequestMapping(value = "/updateTagById")//根据tag_id修改tag
    public String updateTagById(int tag_id, String tag_name, Integer tag_group, String tag_start_time, String tag_end_time,
                                int tag_office, int tag_weight, int oid, int role, Model model){
        return tagService.updateTagById(tag_id, tag_name, tag_group, tag_start_time, tag_end_time,
                tag_office, tag_weight, oid, role, model);
    }

@RequestMapping(value = "/listAllTags")
    public String listAllTags(Model model){
    return tagService.listAllTags(model);
}

@RequestMapping(value = "/getTagById")//根据tag_id获得tag
    public String getTagById(int tag_id, int tag_group, int tag_office, int tag_weight, int oid, int role, Model model){
    return tagService.getTagById(tag_id, tag_group, tag_office, tag_weight, oid, role, model);
    }
@RequestMapping(value = "/getTagByIdNoAuth")//根据tag_id获得tag不带权限
    public String getTagByIdNoAuth(int tag_id, int tag_group, int tag_office, int tag_weight, int oid, int role, Model model){
        return tagService.getTagByIdNoAuth(tag_id, tag_group, tag_office, tag_weight, oid, role, model);
    }

@RequestMapping(value = "/getTagsByPatientIdAndGroupId")//查看一个人在某分组中的tag
    public String getTagsByPatientIdAndGroupId(int patient_id, int tag_group, Model model){
        return tagService.getTagsByPatientIdAndGroupId(patient_id, tag_group, model);
    }

@RequestMapping(value = "/getTagByName")
    public String getTagByName(String tag_name, Model model){
    return tagService.getTagByName(tag_name,model);
}

@RequestMapping(value = "/getTagsCount")//所有标签个数(除删除的外)
    public String getTagsCount(Model model){
    String num = tagService.getTagsCount(model);
    return num;
}

}
